/* 
 * File:   Calculos.h
 * Author: thiago
 *
 * Created on 4 de Abril de 2010, 14:11
 */

#ifndef _CALCULOS_H
#define	_CALCULOS_H

#include "../Particula.h"

#define GLOBAL          extern
#define ABS(a)		(((a) < 0) ? -(a) : (a))

extern "C" void launch_CalculaIDGridCell(unsigned int blocksPerGrid, unsigned int threadsPerBlock,
        float3* posicoes, unsigned int* values, unsigned int* keys, int numeroParticulas,
        int numColunas, float deltaX, float deltaY, unsigned int* count, float XminGrid, float YminGrid);

extern "C" void launch_ZeraCountEOffSet(unsigned int blocksPerGrid, unsigned int threadsPerBlock, int numeroCelulas,
        unsigned int* count, unsigned int* offSet);

extern "C" void launch_FindNeighbors(unsigned int blocksPerGrid, unsigned int threadsPerBlock, float3* posicoesParticulasT, float3*  posicoesParticulasT2, Particula* particulas, Particula* particulas2, unsigned int* values, unsigned int* keys,
        unsigned int* count, unsigned int* offSet, int resolucaoGridX, int resolucaoGridY, const int numeroParticulas, float deltaX, float deltaY,
        float massaEspecificaInicial, float massa, float h, float3* forcaPressaoVetorDevice, float3* forcaAceleracaoVetorDevice,
        float3* forcaViscosidadeVetorDevice, float XminGrid, float XmaxGrid, float YminGrid, float YmaxGrid, float3 gravidade);

GLOBAL int threadsPerBlock;
GLOBAL int blocksPerGrid;
GLOBAL int totalParticulas;
GLOBAL int totalCelulasGrid;
GLOBAL int resolucaoGridX;
GLOBAL int resolucaoGridY;
GLOBAL int resolucaoPartY;
GLOBAL float XminGrid;
GLOBAL float XmaxGrid;
GLOBAL float YminGrid;
GLOBAL float YmaxGrid;
GLOBAL float deltaXGrid;
GLOBAL float deltaYGrid;
GLOBAL float deltaXPart;
GLOBAL float deltaYPart;
GLOBAL float massa;
GLOBAL float massaEspecificaInicial;
GLOBAL float h;
GLOBAL float3 gravidade;
const float constGas = 0.01;
const float coeficienteViscosidade = 0.5;
const float passoIntegracao = 0.1;
GLOBAL unsigned int* keys;
GLOBAL unsigned int* values;
GLOBAL unsigned int* count;
GLOBAL unsigned int* offSet;
GLOBAL unsigned int* keysDevice;
GLOBAL unsigned int* valuesDevice;
GLOBAL unsigned int* countDevice;
GLOBAL unsigned int* offSetDevice;
GLOBAL float3* posicoesParticulas;
GLOBAL float3* posicoesParticulas2;
GLOBAL float3* posicoesParticulasT;
GLOBAL float3* posicoesParticulasT2;
GLOBAL Particula* particulas;
GLOBAL Particula* particulas2;
GLOBAL Particula* particulasT;
GLOBAL Particula* particulasT2;
GLOBAL float3* forcaPressaoVetor;
GLOBAL float3* forcaAceleracaoVetor;
GLOBAL float3* forcaViscosidadeVetor;
GLOBAL float3* forcaPressaoVetorDevice;
GLOBAL float3* forcaAceleracaoVetorDevice;
GLOBAL float3* forcaViscosidadeVetorDevice;
GLOBAL Particula* particulasDevice;
GLOBAL Particula* particulasDevice2;
GLOBAL bool VBO_Ativo;
GLOBAL const bool gpu;
GLOBAL GLuint positionsVBO;
GLOBAL float3* VBO;
GLOBAL GLuint positionsVBO2;
GLOBAL float3* VBO2;

GLOBAL void buildVBO();
GLOBAL void deleteVBO();
void radixSort();
void scan();
float calculaMassaEspecifica(int i, int j, float h, int indiceAtual);
float3 calculaFocaPressao(int i, int j, float h, int indiceAtual);
float3 calculaFocaVisc(int i, int j, float h, int indiceAtual);
void corrigePosicao(int posicaoParticulaAtual);
void defineVetoresTeT2();
void organizaEstruturaDeDados();
void calculaOnCPU(void);
void CalculaKernelsOnGPU();


#endif	/* _CALCULOS_H */

